function PurchaseInfo_Code() {
	var buffer = new StringBuffer();
	buffer.append('<div id="purchaseinfo" class="orderinfo" type="1"><div class="line100"><font class="blacks">采购单号：</font><font id="purchasenum">加载中...</font></div><div class="line100"><font class="blacks">供应商名称：</font><font id="suppliername"></font></div><div class="line100"><font class="blacks">总金额：</font><font id="allmoney"></font></div><div class="line100"><font class="blacks">采购人：</font><font id="realname"></font></div><div class="line100"><font class="blacks">采购时间：</font><font id="buydate"></font></div><div class="line100"><font class="blacks">创建时间：</font><font id="createdate"></font></div><div class="line100"><font class="blacks">备注：</font><font id="bak"></font></div></div>');
	
	buffer.append('<div class="ordertab border-top-bottom"><table><tr><td width="20%">产品名称</td><td width="20%">仓库名称</td><td width="10%">单位</td><td width="15%">价格</td><td width="10%">数量</td><td width="10%">折扣</td><td width="15%">总金额</td></tr></table></div>');
	buffer.append('<div class="productpanel">');
	buffer.append('<div class="panels"><div id="loading10"><img src="img/loading.gif"/></div></div>');
	buffer.append('</div>');
	return buffer.toString();
};



function Init_PurchaseDetail(){
	
	var data = {};
    data.act = "One_Purchase";
    data.id = obj.attr("id");
    data.userid=userid;
	data.comid=comid;
	data.source=source;
	data.sign=GetSign(data.act);
    mui.getJSON(crm_domain, data, function(json) {
    	var purchase = json.data.purchase;
    	var str="";
    	var isselect="";
        $("#purchasenum").html(purchase.Num);
        $("#suppliername").html(purchase.SupplierName);
        $("#allmoney").html(purchase.AllMoney.toFixed(2));
        $("#realname").html(purchase.RealName);
        $("#buydate").html(purchase.BuyDate.ToTime());
        $("#createdate").html(purchase.CreateDate.ToTime());
        $("#bak").html(purchase.Bak.ToString());
        $("#purchaseinfo").attr("type",purchase.Type);
        //初始化拓展字段
        //Init_ExpandTags(tags);
        $(".panels").html(Purchase_Info_Data1(json.data.purchasedetail));
    });
};

function Purchase_Info_Data1(data) { 
var buffer = new StringBuffer();
$.each(data,function(i,info){
buffer.append('<table><tr>');
buffer.append('<td width="20%">'+info.ProductName+'</td>');
buffer.append('<td width="20%">'+info.LibraryName+'</td>');
buffer.append('<td width="10%">'+info.Unit+'</td>');
buffer.append('<td width="15%">'+info.BuyPrice.toFixed(2)+'</td>');
buffer.append('<td width="10%">'+info.Count+'</td>');
buffer.append('<td width="10%">'+info.Percent+'</td>');
buffer.append('<td width="15%">'+info.AllMoney.toFixed(2)+'</td>');
buffer.append('</tr></table>');
});
if(data.length==0){
buffer.append('<tr><td class="center">主人，没有找到您需要的数据！</td></tr>');
}
return buffer.toString();
};

function PurchaseTool()
{
	if($("#purchaseinfotool").length>0)
	{
		$("#purchaseinfotool").show();
	}else
	{
		$("body").append('<div id="purchaseinfotool" class="customertool" style="height:120px;"><ul><li id="purchaseedit">修改采购单</li><li id="purchasedelete2" class="hidden">删除采购单</li></ul></div>');
		//初始化工具条
		
        
		get("purchaseedit").addEventListener("tap",function(){
        	OpenWindow(3,"采购单","保存",function(){
				Save_Purchase();
			});
			$("#contentlist3").html(PurchaseAdd_Code(obj.attr("id"),"purchase",$("#purchaseinfo").attr("type")));
			Init_PurchaseAdd();
			$("#purchaseinfotool").hide();
        });
        
        get("purchasedelete2").addEventListener("tap",function(){
        	$("#purchaseinfotool").hide();
        	plus.nativeUI.confirm("确定要删除吗？", function(event){
				if(event.index==1)
				{
					var data = {};
				    data.act = "Delete_Purchase";
				    data.ids = obj.attr("id");
				    data.userid=userid;
					data.comid=comid;
					data.source=source;
					data.sign=GetSign(data.act);
				    mui.getJSON(crm_domain, data, function(json) {
				    	plus.nativeUI.toast(json.msg);
						if(json.state)
						{
							CloseWindow();
							obj.remove();
						}
				    });	
				}
			},"提示", ["取消","确认"]); 
        });
	}
};
